from typing import List, TYPE_CHECKING, Union, Callable, ClassVar,Optional
from pydantic import EmailStr
from datetime import datetime
from sqlmodel import  SQLModel,text,Column,TEXT,Field,Relationship
from .base import SQLModelBase
from .resBase import BaseResponse
import sqlalchemy as sa
from enum import Enum

# 添加枚举类定义
class AuthStatusEnum(str, Enum):
    PENDING = "pending"  # 待审核
    APPROVED = "approved"  # 通过
    REJECTED = "rejected"  # 拒绝

class AuthTypeEnum(str, Enum):
    REAL_NAME = "realname"  # 实名认证
    EDUCATION = "education"  # 学历认证

if TYPE_CHECKING:    
    from .user import User
       
# 用户认证
class UserAuthBase(SQLModel):                  
    authStatus: AuthStatusEnum = Field(
        default=AuthStatusEnum.PENDING,
        title="审核状态", 
        sa_column_kwargs={"comment": "审核状态：待审核、通过、拒绝","name":"auth_status"}
    )    
    authType: AuthTypeEnum = Field(
        title="认证类型", 
        sa_column_kwargs={"comment": "认证类型：实名认证、学历认证","name":"auth_type"}
    )    
    imgList: str | None = Field( max_length=255,title="材料", sa_column_kwargs={"comment": "材料","name":"img_list"})    
    remarks: str | None = Field( max_length=255,title="备注", sa_column_kwargs={"comment": "备注","name":"remarks"})          
    


class UserAuth(UserAuthBase,SQLModelBase, table=True):
    userId: int = Field(foreign_key="users.id",sa_column_kwargs={"comment": "用户唯一id","name":"user_id"})    

    # 定义表参数
    __tablename__: str = "user_auth" 
    __table_args__ = {'comment': '用户认证表'}
    user:"User" = Relationship(back_populates="userauths")

# 用户提交认证
class UserAuthSubmit(SQLModel):                      
    authType: AuthTypeEnum 
    imgList: str 
 

# 用户认证响应
class UserAuthPublic(UserAuthBase,SQLModelBase):
    pass

class UserAuthResponse(BaseResponse):
    data: List[UserAuthPublic] | None  



